home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Frameworks / DropShell Pascal / DSUserProcs.p < prev    next >
Encoding:
Text File  |  1992-06-19  |  7.1 KB  |  225 lines  |  [TEXT/MPS ]

  1. {******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DSUserProcs.p
  5. **
  6. **   Description:    Specific AppleEvent handlers used by the Dropbox
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **
  16. *******************************************************************************
  17. **                      R E V I S I O N   H I S T O R Y
  18. *******************************************************************************
  19. **
  20. **      Date        Time    Author    Description
  21. **    --------    -----    ------    ---------------------------------------------
  22. **    12/09/91            LDR        Added the new SelectFile & UserGlobal userProcs
  23. **                                Modified PostFlight to only autoquit on odoc, not pdoc
  24. **    11/24/91            LDR        Added the userProcs for pdoc handler
  25. **                                Added support for a userDataHandle passed odoc/pdoc routines
  26. **                                We now include the new DSUtils
  27. **    10/30/91            LDR        Modified USES clause for new include & ifc'ed ThP
  28. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  29. **                                Added a bunch of comments for clarification
  30. **    04/08/91    23:58    LDR        Original Version
  31. **
  32. ******************************************************************************}
  33.  
  34. UNIT DSUserProcs;
  35. INTERFACE
  36.  
  37. {$IFC THINK_Pascal}
  38.     USES
  39.         DSGlobals, DSUtils;    {just the DropShell files}
  40. {$ELSEC}
  41.     USES
  42.     { First load standard interface files}
  43.         MemTypes, QuickDraw, 
  44.  
  45.     { Now include the stuff from OSIntf }
  46.         OSIntf, 
  47.  
  48.     { Now Include the stuff from ToolIntf.p }
  49.         ToolIntf, Packages, GestaltEqu, 
  50.  
  51.     { Then any OTHER Toolbox interfaces... }
  52.         Files, Aliases, AppleEvents,
  53.  
  54.     { And finally any files from DropShell }
  55.         DSGlobals, DSUtils;
  56. {$ENDC THINK_Pascal}
  57.     
  58. {---------------------}
  59. {Interface Definitions}
  60. {---------------------}
  61.  
  62.     PROCEDURE InstallOtherEvents;
  63.     
  64.     PROCEDURE OpenApp;
  65.     PROCEDURE QuitApp;
  66.     
  67.     FUNCTION  PreFlightDocs(opening: Boolean; VAR userDataHandle: UNIV Handle): Boolean;
  68.     PROCEDURE OpenDoc( myFSSPtr: FSSpecPtr; opening: Boolean; userDataHandle: UNIV Handle );
  69.     PROCEDURE PostFlightDocs(opening: Boolean; userDataHandle: UNIV Handle);
  70.  
  71.     PROCEDURE SelectFile;
  72.     FUNCTION  InitUserGlobals:Boolean;
  73.     PROCEDURE DisposeUserGlobals;
  74.     
  75. IMPLEMENTATION
  76.  
  77. {$S Main}
  78.  
  79.     {
  80.         This routine is called during init time.
  81.         
  82.         It allows you to install more AEVT Handlers beyond the standard four
  83.     }
  84.     PROCEDURE InstallOtherEvents;
  85.     BEGIN
  86.     END;
  87.     
  88.     {
  89.         This routine is called when an OAPP event is received.
  90.         
  91.         Currently, all it does is set the gOApped flag, so you know that
  92.         you were called initally with no docs, and therefore you shouldn't 
  93.         quit when done processing any following odocs.
  94.     }
  95.     PROCEDURE OpenApp;
  96.     BEGIN
  97.         gOApped := TRUE;
  98.     END;
  99.     
  100.     {
  101.         This routine is called when an QUIT event is received.
  102.         
  103.         We simply set the global done flag so that the main event loop can
  104.         gracefully exit.  We DO NOT call ExitToShell for two reasons:
  105.         1) It is a pretty ugly thing to do, but more importantly
  106.         2) The Apple event manager will get REAL upset!
  107.     }
  108.     PROCEDURE QuitApp;
  109.     BEGIN
  110.         gDone := TRUE;    {All Done!}
  111.     END;
  112.     
  113.     {
  114.         This routine is the first one called when an ODOC or PDOC event is received.
  115.         
  116.         In this routine you would place code used to setup structures, etc. 
  117.         which would be used in a 'for all docs' situation (like "Archive all
  118.         dropped files"). 
  119.         
  120.         Obviously, the opening boolean tells you whether you should be opening
  121.         or printing these files based on the type of event recieved.
  122.         
  123.         userDataHandle is a handle that you can create & use to store your own
  124.         data structs.  This dataHandle will be passed around to the other 
  125.         odoc/pdoc routines so that you can get at your data without using
  126.         globals - just like the new StandardFile.    The shell knows NOTHING
  127.         about this userDataHandle and will do NOTHING to do.  You MUST perform
  128.         all allocation, access and deallocation if you use it.
  129.     
  130.         We also return a boolean to tell the caller if you support this type
  131.         of event.  By default, our dropboxes don't support the pdoc, so when
  132.         opening is FALSE, we return FALSE to let the caller send back the
  133.         proper error code to the AEManager.
  134.     }
  135.     FUNCTION PreFlightDocs(opening: Boolean; VAR userDataHandle: UNIV Handle): Boolean;
  136.     BEGIN
  137.     
  138.         PreFlightDocs := opening;    {we support opening, but not printing - see above}
  139.     END;
  140.     
  141.     {
  142.         This routine is called for each file passed in the ODOC or PDOC event.
  143.         
  144.         In this routine you would place code for processing each file/folder/disk that
  145.         was dropped on top of you.
  146.     }
  147.     PROCEDURE OpenDoc( myFSSPtr: FSSpecPtr; opening: Boolean; userDataHandle: UNIV Handle );
  148.     BEGIN
  149.     END;
  150.     
  151.     {
  152.         This routine is the last routine called as part of an ODOC or PDOC event.
  153.         
  154.         In this routine you would place code to process any structures, etc. 
  155.         that you setup in the PreflightDocs routine.
  156.  
  157.         If you created a userDataHandle in the PreFlightDocs routines, this is
  158.         the place to dispose of it since the Shell will NOT do it for you!
  159.     }
  160.     PROCEDURE PostFlightDocs(opening: Boolean; userDataHandle: UNIV Handle);
  161.     BEGIN
  162.         IF (opening) AND (NOT gOApped) THEN
  163.             gDone := TRUE;    {close everything up when sent an original odoc}
  164.         
  165.         {
  166.             The reason we do not auto quit is based on a recommendation in the
  167.             Apple event Registry which specifically states that you should NOT
  168.             quit on a 'pdoc' as the Finder will send you a 'quit' when it is 
  169.             ready for you to do so.
  170.         }
  171.     END;
  172.  
  173.  
  174.  
  175.     {
  176.         This routine is called when the user chooses "Select File…" from the
  177.         File Menu.
  178.         
  179.         Currently it simply calls the new StandardGetFile routine to have the
  180.         user select a single file (any type, numTypes = -1) and then calls the
  181.         SendODOCToSelf routine in order to process it.  
  182.                 
  183.         The reason we send an odoc to ourselves is two fold: 1) it keeps the code
  184.         cleaner as all file openings go through the same process, and 2) if events
  185.         are ever recordable, the right things happen (this is called Factoring!)
  186.  
  187.         Modification of this routine to only select certain types of files, selection
  188.         of multiple files, and/or handling of folder & disk selection is left 
  189.         as an exercise to the reader.
  190.     }
  191.     PROCEDURE SelectFile;
  192.     VAR
  193.         stdReply: StandardFileReply;
  194.         theTypeList: SFTypeList;
  195.     BEGIN
  196.         StandardGetFile(NIL, -1, theTypeList, stdReply);
  197.         IF (stdReply.sfGood) THEN                {user did not cancel}
  198.             SendODOCToSelf(stdReply.sfFile);    {so send me an event!}
  199.     END;
  200.  
  201. {
  202.     This routine is called during the program's initialization and gives you
  203.     a chance to allocate or initialize any of your own globals that your
  204.     dropbox needs.
  205.     
  206.     You return a boolean value which determines if you were successful.
  207.     Returning false will cause DropShell to exit immediately.
  208. }
  209. FUNCTION InitUserGlobals:Boolean;
  210. BEGIN
  211.     InitUserGlobals := TRUE;    {nothing to do, it we must be successful!}
  212. END;
  213.  
  214. {
  215.     This routine is called during the program's cleanup and gives you
  216.     a chance to deallocate any of your own globals that you allocated 
  217.     in the above routine.
  218. }
  219. PROCEDURE DisposeUserGlobals;
  220. BEGIN
  221.     {nothing to do for our sample dropbox}
  222. END;
  223.     
  224. END.
  225.